package StudyCode.summary.myfile;

import java.util.Arrays;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class ConvertBooleanArrayByte {
	public static void main(String[] args) {
		boolean[] booleans = new boolean[]{true, true, true, false, false, false, true, false};
		System.out.println(Arrays.toString(booleans));
		System.out.println(fromBooleanArray(booleans));
	}

	private static byte fromBooleanArray(boolean[] a) {
		byte b = 0;
		if (a[7])
			b += 1;
		if (a[6])
			b += 2;
		if (a[5])
			b += 4;
		if (a[4])
			b += 8;
		if (a[3])
			b += 16;
		if (a[2])
			b += 32;
		if (a[1])
			b += 64;
		if (a[0])
			b += 128;
		return b;
	}
}
